﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace FDSimpleModelGenerator.Common.Mvc.PageModels
{
    /// <summary>
    /// 检测是否无需登录、注册
    /// </summary>
    public class LoginBaseModel : PageModel
    {
        /// <summary>
        /// 只有此时可跳转到login
        /// </summary>
        /// <param name="context"></param>
        public override void OnPageHandlerExecuted(PageHandlerExecutedContext context)
        {
            var logined = context.HttpContext.User.Identity.IsAuthenticated;
            if (logined)
            {
                context.Result = new RedirectResult("/");
                return ;
            }
            base.OnPageHandlerExecuted(context);
        }

        //public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        //{
        //    return base.OnPageHandlerExecutionAsync(context, next);
        //}

        //public override void OnPageHandlerExecuting(PageHandlerExecutingContext context)
        //{
        //    base.OnPageHandlerExecuting(context);
        //}
    }
}
